package libtool65.o65;

import java.io.IOException;
import java.io.InputStream;

public class CodeBlock {
	int base;
	byte[] data;

	public void read(InputStream file, SegmentDef segment) throws IOException, CodeReadException {
		base = segment.getBase();
		data = new byte [segment.getSize()];
		int bytes_read = file.read(data);
		if (bytes_read != data.length)
			throw new CodeReadException(segment.getSize(), bytes_read);
	}

	public int copyTo(byte[] code_block, int current_offset) {
		for (int i = 0; i < data.length; i++)
			code_block[current_offset+i] = data[i];
		return current_offset + data.length;
	}

}
